﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace job
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "")
            {
                Login();
                this.Close();
            }   
            else
            {
                MessageBox.Show("输入为空，请重新输入");
            }
        }
        //登陆方法，验证是否允许登录
        public void Login()
        {
            //管理员
            if(radioButton1admin.Checked==true)
            {
                Dao dao = new Dao();
                //  string sql = "select * from job_admin where id='"+textBox1.Text+ "' and password='" + textBox2.Text + "'";
                string sql = $"select * from job_admin where id='{textBox1.Text} 'and password='{ textBox2.Text}'";

                IDataReader dc = dao.read(sql);
                {
                    if (dc.Read())
                    {
                        MessageBox.Show("登陆成功");
                        admin1 job = new admin1();//实例化用户窗体
                        this.Hide();
                        job.ShowDialog();
                        this.Show();//打开新窗体
                    }
                    else
                    {
                        MessageBox.Show("登陆失败");

                    }
                }
                dao.DaoClose();
            }
            //企业
            if (radioButton2company.Checked==true)
            {
                Dao dao = new Dao();
                //  string sql = "select * from job_admin where id='"+textBox1.Text+ "' and password='" + textBox2.Text + "'";
                string sql = $"select * from company_admin where id='{textBox1.Text} 'and password='{ textBox2.Text}'";

                IDataReader dc = dao.read(sql);
                if (dc.Read())
                {
                    data.U_ID = dc["id"].ToString();
                    data.U_name = dc["name"].ToString();

                    MessageBox.Show("登陆成功");
                    company1 company = new company1();//实例化用户窗体
                    this.Hide();
                    company.ShowDialog();
                    this.Show();//打开新窗体
                }
                else
                {
                    MessageBox.Show("登陆失败");
                   
                }
                dao.DaoClose();
            }
        //    MessageBox.Show("请先选中单选框");
            
        }
        private void radioButton2company_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void radioButton1admin_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
          
        }
    }
}
